<%@page import="study.itwill.team5.board.BoardItem"%>
<%@page import="study.itwill.team5.board.Board"%>
<%@page import="study.itwill.team5.house.RoomItem"%>
<%@page import="study.itwill.team5.house.ImageItem"%>
<%@page import="study.itwill.team5.house.TelItem"%>
<%@page import="study.itwill.team5.house.HouseItem"%>
<%@page import="study.itwill.team5.house.House"%>
<%@page import="study.itwill.common.PatternChecker"%>
<%@page import="study.itwill.common.DBHandler"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%
	String seq = request.getParameter("seq");
	String city_seq = request.getParameter("city");

	/** 파라미터의 유효성 검사 */
	if(!PatternChecker.isValue(seq)) {
		out.print("<script type='text/javascript'>alert('민박 일련번호 파라미터가 없습니다.');history.back();</script>");
		return;
	}
	
	if(!PatternChecker.isNum(seq)) {
		out.print("<script type='text/javascript'>alert('민박 일련번호 파라미터가 형식에 맞지 않습니다.');history.back();</script>");
		return;
	}
	
	if(!PatternChecker.isValue(city_seq)) {
		out.print("<script type='text/javascript'>alert('도시 일련번호 파라미터가 없습니다.');history.back();</script>");
		return;
	}
	
	if(!PatternChecker.isNum(city_seq)) {
		out.print("<script type='text/javascript'>alert('도시 일련번호 파라미터가 형식에 맞지 않습니다.');history.back();</script>");
		return;
	}
	
	int house_seq = Integer.parseInt(seq);
	int n_city_seq = Integer.parseInt(city_seq);
	
	
%>
<%@ include file="../dbcon.jsp"%>
<%
	
	// 민박 데이터 조회
	House house = new House();
	HouseItem item = house.viewHouse(house_seq);
	
	// 연락처 데이터 조회
	ArrayList<TelItem> t_item = house.telList(house_seq);
	
	// 이미지 데이터 조회
	ArrayList<ImageItem> i_item = house.imageList(house_seq);
	
	// 룸 데이터 조회
	ArrayList<RoomItem> r_item = house.roomList(house_seq);
	
	if (item == null) {
		out.print("<script type='text/javascript> alert('데이터조회에 실패했습니다. 잠시후 다시 시도해 주세요.'); history.back();</script>");
		return;
	}
%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp" %>
  </head>
  <body>
  	<%@ include file="../menu.jsp" %>
  	<%DBHandler.disconnect();%>
    <!-- 웹 페이지 영역 -->
    <div class="container">
    	<div class="page-header">
    		<h1>
    			민박 정보 보기
    		</h1>
    	</div>
    	
    	<form id="frmHouseView" class="form-horizontal" role="form" method="post" action="">
    	
    	<!-- 민박 번호 자동 입력 -->
    	<input type="hidden" name="seq" value="<%=house_seq%>" />
    	<input type="hidden" name="city_seq" value="<%=n_city_seq %>" />
    		<fieldset>
    		<!-- 입력양식 -->
    		<div class="form-group">
    			<label for="name" class="col-md-2 control-label">민박 이름</label>
    			<div class="col-md-10">
    				<p class="form-control-static"><%=item.getName()%></p>
    			</div>
    		</div>
    		<!-- // 입력양식 -->
    		
    		<!-- 입력양식 -->
    		<div class="form-group">
    			<label for="userid" class="col-md-2 control-label">주소 : 국가</label>
    			<div class="col-md-10">
    				<p class="form-control-static"><%=item.getAddress1()%></p>
    			</div>
    		</div>
    		<!-- // 입력양식 -->
    		
    		<!-- 입력양식 -->
    		<div class="form-group">
    			<label for="grade" class="col-md-2 control-label">주소 : 도시</label>
    			<div class="col-md-10">
    				<p class="form-control-static"><%=item.getAddress2()%></p>
    			</div>
    		</div>
    		<!-- // 입력양식 -->
    		
    		<!-- 입력양식 -->
    		<div class="form-group">
    			<label for="idnum" class="col-md-2 control-label">주소 : 상세주소</label>
    			<div class="col-md-10">
    				<p class="form-control-static"><%=item.getAddress3()%></p>
    			</div>
    		</div>
    		<!-- // 입력양식 -->
    		
    		<!-- 입력양식 -->
    		<div class="form-group">
    			<label for="birthdate" class="col-md-2 control-label">주소 : 기타</label>
    			<div class="col-md-10">
    				<p class="form-control-static"><%=item.getAddress4()%></p>
    			</div>
    		</div>
    		<!-- // 입력양식 -->
    		
    		<!-- 입력양식 -->
    		<div class="form-group">
    			<label for="tel" class="col-md-2 control-label">이메일</label>
    			<div class="col-md-10">
    				<p class="form-control-static"><a href="mailto:<%=item.getEmail()%>"><%=item.getEmail()%></a></p>
    			</div>
    		</div>
    		<!-- // 입력양식 -->
    		
    		<!-- 입력양식 -->
    		<div class="form-group">
    			<label for="height" class="col-md-2 control-label">홈페이지</label>
    			<div class="col-md-10">
    				<p class="form-control-static"><a href="<%=item.getHomepage()%>" target="_blink"><%=item.getHomepage()%></a></p>
    			</div>
    		</div>
    		<!-- // 입력양식 -->
    		<!-- 입력양식 -->
    		<div class="form-group">
    			<label for="weight" class="col-md-2 control-label">위도</label>
    			<div class="col-md-10">
    				<p class="form-control-static"><%=item.getLat()%></p>
    			</div>
    		</div>
    		<!-- // 입력양식 -->
    		<!-- 입력양식 -->
    		<div class="form-group">
    			<label for="weight" class="col-md-2 control-label">경도</label>
    			<div class="col-md-10">
    				<p class="form-control-static"><%=item.getLon()%></p>
    			</div>
    		</div>
    		<!-- // 입력양식 -->
    		<!-- 입력양식 -->
    		<div class="form-group">
    			<label for="weight" class="col-md-2 control-label">정보</label>
    			<div class="col-md-10">
    				<p class="form-control-static"><%=item.getInfo()%></p>
    			</div>
    		</div>
    		<!-- // 입력양식 -->
    		<!-- 입력양식 -->
    		<div class="form-group">
    			<label for="tel" class="col-md-2 control-label">연락처</label>
    			<div class="col-md-10">
<%
	if (t_item != null) {
		for (int i=0; i<t_item.size(); i++) {
			TelItem item2 = t_item.get(i);
%>
			
    				<p class="form-control-static"><%=item2.getTel()%></p>
    		
<%
		}
		
	}
%>
				</div>	
    		</div>
    		<!-- // 입력양식 -->
    	    <!-- 입력양식 -->
    		<div class="form-group">
    			<label for="image" class="col-md-2 control-label">이미지</label>
    			<div class="col-md-10">
<%
	if (i_item != null) {
		for (int i=0; i<i_item.size(); i++) {
			ImageItem item3 = i_item.get(i);
%>
			
    				<p class="form-control-static"><%=item3.getImage_url()%></p>
    		
<%
		}
		
	}
%>
				</div>
    		</div>
    		<!-- // 입력양식 -->	
    		
    		<!-- 입력양식 -->
    		<div class="form-group">
    			<label for="image" class="col-md-2 control-label">룸정보</label>
    				<div class="col-md-10">
						<table class="table table-striped">
							<thead>
								<tr class="warning">
									<th class="text-center">방이름</th>
									<th class="text-center">최대 인원</th>
									<th class="text-center">비수기 가격</th>
									<th class="text-center">성수기 가격</th>
								</tr>
							</thead>
							<tbody>
								<%
									if (r_item.size() < 1) {
								%>
								<tr>
									<td colspan="10">
										<p class="text-center text-warning" style="height: 100px">
										저장된 데이터가 없습니다.</p>
									</td>
								</tr>
								<%
									} else {
									for (int i=0; i<r_item.size(); i++) {
										RoomItem item4 = r_item.get(i);
								%>
								<tr class="text-center">
									<td><%=item4.getName()%></td>
									<td><%=item4.getLimit_person()%></td>
									<td><%=item4.getOff_price()%></td>
									<td><%=item4.getOn_price()%></td>
								</tr>
								<%
									} // end for
								} // end if
								%>
							</tbody>
						</table>
					</div>
				</div>
    		<!-- // 입력양식 -->	

    		<div class="form-group">
    			<div class="col-md-offset-2 col-md-10">
    				<div class="row">
    					<div class="col-md-4">
    						<a href="listHouse.jsp?city=<%=city_seq%>" class="btn btn-primary btn-block">목록보기</a>
    					</div>
    					<div class="col-md-4">
    						<button type="submit" id="edit" formaction="editHouse.jsp" formmethod="post" class="btn btn-info btn-block">수정하기</button>
    					</div>
    					<div class="col-md-4">
    						<button type="submit" id="delete" formaction="deleteHouseOk.jsp" formmethod="post" class="btn btn-danger btn-block">삭제하기</button>
    					</div>
    				</div>
    			</div>
    		</div>
    		</fieldset>
    	</form>
    </div>
    
    <!-- Javascript -->
    <script src="/italia/assets/js/jquery.js"></script>
    <script src="/italia/assets/js/bootstrap.min.js"></script>
    <!-- 형식검사 클래스 참조 -->
    <script src="/italia/assets/js/string.js"></script>
    <!-- 구현부분 -->
    <script type="text/javascript">
 // jquery main()
	$(function() {
		// id 속성이 frmHouseView인 대상에 대한 전송 이벤트
		$("#delete").click(function() {
		// 사용자에게 물어본다.
    		if (!confirm("정말 삭제하시겠습니까?")) {
    			// "취소"를 선택한 경우 처리 중단
    			return false;
    		}
		});
	});
    </script>
  </body>
</html>